<template>
	<view class="container">		
		<web-view 
			:src="webViewUrl"
			:webview-styles="webviewStyles"
		></web-view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			webViewUrl: 'https://api.eachidc.com/chat.html',
			webviewStyles: {
				progress: {
					color: '#FD5674'
				}
			},
			info:{}
		}
	},
	onLoad() {
		this.postuserinfo()
	},
	methods: {
		postuserinfo() {
			this.$Request({
				method: 'POST',
				url: '/api/personal/myIndex',
				data: {},
				ismsg: false,
			}).then(res => {
				if (res.code == 1) {
					this.info = res.data 
					this.webViewUrl = 'https://api.eachidc.com/chat.html?name=' + this.info.user.mobile +'&uid='+this.info.user.mobile
					console.log(this.webViewUrl)
				}
			})
		
		},
		// 向webview发送消息
		sendToWebview(data) {
			const pages = getCurrentPages()
			const currentPage = pages[pages.length - 1]
			const webview = currentPage.$getAppWebview()
			
			webview.evalJS(`receiveFromApp(${JSON.stringify(data)})`)
		}
	},
	onBackPress() {
		// 处理返回按钮事件
		this.sendToWebview({type: 'back'})
		return true // 阻止默认返回行为
	}
}
</script>

<style>
.container {
	height: 100vh;
	display: flex;
	flex-direction: column;
}
</style>